<?php
/**
 * @Author: Marte
 * @Date:   2017-08-11 21:10:59
 * @Last Modified by:   Marte
 * @Last Modified time: 2017-08-20 08:07:07
 */
require '../config_connect.php';//引入数据库
require '../../common/register.func.php';//引入函数库
session_start();
$_username=$_POST['username'];
$_password=$_POST['password'];
$_code=$_POST['code'];
$_phone=$_POST['phone'];
$_email=$_POST['email'];
$_ss=$_POST['check'];
if(!isset($_POST["submit"])){
      exit('非法访问!');
  }
if($_ss!='on')
{
   echo "<script>alert('请勾选用户服务协议');location='../../author_register.php?error=3'</script>";
}
_check_username($_username);
_check_password($_password);
_check_email($_email);
// _check_passwd($_password,$_prepassword);
$regtime=time();
$username=md5(trim($_POST['username']));//去掉前后的空格后，在加密
$password=md5(trim($_POST['password']));
$uniqute=md5($username.$password);//唯一标识
$token=md5($username.$password.$regtime);//激活码

if(!($_SESSION['code']==$_code))
{
  //如果验证码不正确，
  echo "<script>location='../../author_register.php?error=2'</script>";
}
else
{
  $_sql="select * from author";

  $_result=$_mysql->query($_sql);

  //得到关联数组
  while ( $_assoc=$_result->fetch_assoc())
  {
        if($_assoc['username']==$_username||$_assoc['email']==$_email)
               {
                    echo "<script>location='../../author_register.php?error=2'</script>";
               }

  }


    $sql1 = "INSERT INTO author (username, password,phone, email,token,uniqute)
    VALUES ('$_username', '$_password','$_phone', '$_email','$token','$uniqute')";
    $_result=$_mysql->query($sql1);
    if($_result)
    {
      echo "<script>alert('注册成功！');location='../../author_dl.php';</script>";
    }else
    {
      echo "<script>alert('注册失败了！');";
    }


}


?>




















